﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHealthOnline.Business;
using MyHealthOnline.Dal.Generated.EntityClasses;

namespace MyHealthOnline.Specialist.Controls
{
    public partial class Questionnaire : System.Web.UI.UserControl
    {
        public int ConsultId
        {
            get
            {
                if (ViewState["ConsultId"] == null)
                {
                    return -1;
                }
                return Convert.ToInt32(ViewState["ConsultId"].ToString());
            }
            set
            {
                ViewState["ConsultId"] = value;
            }
        }
        public ConsultEntity Consult
        {
            get
            {
                return ConsultBusiness.GetConsult(ConsultId);
            }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ddlQuestionnaire.DataTextField = "QuestionText";
                ddlQuestionnaire.DataValueField = "Id";
                ddlQuestionnaire.DataSource = QuestionnaireBusiness.GetQuestionnaires();
                ddlQuestionnaire.DataBind();

                if (ddlQuestionnaire.Items.Count == 0)
                {
                    ddlQuestionnaire.Visible = false;
                    lblNoQuestionnaires.Visible = true;
                }
                else
                {
                    ddlQuestionnaire.Visible = true;
                    lblNoQuestionnaires.Visible = false;
                }
            }
        }

        protected void btnSendQuestionnaire_Click(object sender, EventArgs e)
        {
            int questionId = Convert.ToInt32(ddlQuestionnaire.SelectedValue);
            QuestionnaireBusiness.SendQuestionnaire(questionId, ConsultId);
            ddlQuestionnaire.ClearSelection();

            WebServiceHO webService = new WebServiceHO();
            webService.Notify(Consult.Specialist.Email, Consult.Pacient.Email,
                "New Questionnaire added to consult. Please verify your account.",
                "New questionnaire added");
        }
    }
}